package fzdy.core.dao.impl;

import org.hibernate.SessionFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.persistence.EntityManagerFactory;

@Configuration
public class HibernateConfig {
    /**
     * 配置SessionFactory
     */
    @Bean
    public SessionFactory sesssionFactory(EntityManagerFactory entityManagerFactory) {
        if (entityManagerFactory.unwrap(SessionFactory.class) == null) {
            throw new NullPointerException("factory is not a hibernate factory");
        } else {
            return entityManagerFactory.unwrap(SessionFactory.class);
        }
    }
}
